<?php 
$GLOBALS['Md'] = "RHEID348";
$GLOBALS['Pd'] = "B";
require_once($_SERVER['DOCUMENT_ROOT']."/defaultconf.mex");
MYTCONN();
if (!isset($_POST['iveDepartment'])) {
	echo '<div align="center" style="margin:20px"> Escolha um departamento / loja </div>';
	echo '<div align="center">';
		$qrDepartments = "SELECT ref AS ID, name AS NAME FROM systemoffice.main_offices WHERE type IN (1,2,5)";
		mn_field('select','ED','iveDepartment','',$qrDepartments,' ','','" style="margin:20px');
	echo '</div><div align="center">';
		mn_field('button','ED','iveSubmit','Continuar','','','','" style="margin:20px" onclick="
			document.ivt_regentry.action=\'Modules/RHEID348/lib/elem_frmentry.php\';
			subform(\'ivt_regentry\',\'regoption\');');
	echo '</div>';
	} else {
	$GET = $GLOBALS['MYT']->db_array("SELECT 
						iviID, ivcID, CONCAT(incCode,IF(main_offices.ref>10,office_number,LEFT(UPPER(main_offices.name),4)),YEAR('{$sysTime}'),LPAD(iviID,4,'00')) AS iviCode, iviName, iveDescription,
						iveQuant AS COL3
			FROM systemoffice.inventory_items
			LEFT OUTER JOIN systemoffice.inventory_entries ON iviID = iveItem AND  iveInventory = 1 AND iveDepartment = {$_POST['iveDepartment']}
			LEFT OUTER JOIN systemoffice.main_offices ON iveDepartment = main_offices.ref
			LEFT OUTER JOIN systemoffice.inventory_cat ON ivcID = iveCat");
	$GETdt = $GLOBALS['MYT']->db_array("SELECT iviID, ivcID, CONCAT(incCode,IF(main_offices.ref>10,office_number,LEFT(UPPER(main_offices.name),4)),YEAR('{$sysTime}'),LPAD(iviID,4,'00')) AS iviCode, iviName 
		FROM systemoffice.inventory_items
		INNER JOIN systemoffice.inventory_cat ON iviCat = ivcID
		INNER JOIN systemoffice.main_offices ON {$_POST['iveDepartment']} = main_offices.ref ");
	$CGET = $GET[0];
		mn_field('hidden','ED','iveTotal',$CGET,'','','','');
		mn_field('hidden','ED','iveDepartment',$_POST['iveDepartment'],'','','','');
	echo '<table width="98%">
		<tr height="20"><td>Codigo/Etiqueta</td><td>Artigo</td><td>Descritivo</td><td>Quantidade</td></tr>
		<tr><td colspan="8" style="background-color:#000000" height="1"></td></tr>';
	
	for ($i=1;$i<=$CGET;$i++) {
		if (!isset($GET[$i]['COL3'])) { 
			$GET[$i]['COL3'] = '0'; 
			$GET[$i]['ivcID'] = $GETdt[$i]['ivcID'];
			$GET[$i]['iviID'] = $GETdt[$i]['iviID'];
			$GET[$i]['iviCode'] = $GETdt[$i]['iviCode'];
			}
		mn_field('hidden','ED','iveCat'.$i,$GET[$i]['ivcID'],'','','','');
		mn_field('hidden','ED','iveItem'.$i,$GET[$i]['iviID'],'','','','');
		echo '<tr style="background-color:'.gridlines($i).'">
		<td>'.$GET[$i]['iviCode'].'</td>
		<td>'.$GET[$i]['iviName'].'</td>
		<td>'; mn_field('text','ED','iveDescription'.$i,$GET[$i]['iveDescription'],'30','30','','');
		echo '</td>
		<td>'; mn_field('text','ED','iveQuant'.$i,$GET[$i]['COL3'],'6','6','','INPNUM');
		echo '</td>
	</tr>';
		}
	echo '</table>';
	} 